package com.zys.el.time.mq.service;

import com.alibaba.fastjson2.JSONObject;
import com.zys.el.time.constants.MQConstants;
import com.zys.el.time.mq.constants.ModeType;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class SendMsgService {
    @Resource
    private RabbitTemplate rabbitTemplate;

    /**
     * 存入消息队列查询下一页
     *
     * @param id    查询帖子分页则传频道id；查询评论分页则传帖子id
     * @param MQkey MQ键
     * @param page  要查的页
     * @param size  页大小
     * @param type  类型
     * @apiNote 默认调用对应type的service的getPage方法
     */
    public void pushMQAndQueryNext(Long id, String MQkey, int page, int size, String type) {
        // 存入消息队列，查下一页
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", id.toString());
        jsonObject.put("page", page);
        jsonObject.put("size", size);
        jsonObject.put("type", type);

        rabbitTemplate.convertAndSend(MQConstants.QUERY_PAGE_KEY, jsonObject.toString());
    }

    public void pushMQAndQueryNextScroll(Long id, Long max, int offset, int size, String type) {
        // 存入消息队列，查下一页
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", id.toString());
        jsonObject.put("offset", offset);
        jsonObject.put("max", max);
        jsonObject.put("size", size);
        jsonObject.put("type", type);

        rabbitTemplate.convertAndSend(MQConstants.QUERY_SCROLL_KEY, jsonObject.toString());
    }


}
